home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / grail / code.lua next >
Encoding:
Text File  |  2005-07-16  |  5.6 KB  |  179 lines

  1.  
  2. file_include('script/share/prog_border.lua')
  3.  
  4. -- -----------------------------------------------------------------
  5. -- Init
  6. -- -----------------------------------------------------------------
  7. local function prog_init()
  8.     initModels()
  9.     sound_playMusic("music/rybky04.ogg")
  10.     local pokus = getRestartCount()
  11.  
  12.     --NOTE: a final level
  13.     small:setGoal("goal_alive")
  14.     big:setGoal("goal_alive")
  15.     for key, item in pairs(getModelsTable()) do
  16.         if item:getH() == 2 and item:getW() == 2 then
  17.             item:setGoal("goal_out")
  18.         end
  19.     end
  20.  
  21.     -- -------------------------------------------------------------
  22.     local function prog_init_room()
  23.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  24.  
  25.         room.uztovedi = 0
  26.         room.jestejeden = 0
  27.         room.uztobude = 0
  28.         room.tusili = 0
  29.         if pokus > 7 then
  30.             if odd(pokus) then
  31.                 room.uvod = -1
  32.                 room.pokr = 20 + random(20)
  33.             else
  34.                 room.uvod = 20 + random(25)
  35.                 room.pokr = -1
  36.             end
  37.         else
  38.             room.uvod = 15 + random(20)
  39.             room.pokr = 20 + random(50)
  40.         end
  41.  
  42.         return function()
  43.             local remain = 0
  44.             for key, item in pairs(getModelsTable()) do
  45.                 if item:getH() == 2 and item:getW() == 2 then
  46.                     if item.X == aura.X and item.Y == aura.Y + 1 then
  47.                         item:setAnim("default", 1)
  48.                         if room.uztovedi < 3 and item ~= light then
  49.                             room.uztovedi = 3
  50.                         end
  51.                     else
  52.                         item:setAnim("default", 0)
  53.                     end
  54.                     if not item:isOut() then
  55.                         remain = remain + 1
  56.                     end
  57.                 end
  58.             end
  59.             pom2 = 0
  60.             if no_dialog() and isReady(small) and isReady(big) then
  61.                 if room.uvod > 0 then
  62.                     room.uvod = room.uvod - 1
  63.                 elseif room.uvod == 0 then
  64.                     room.uvod = -1
  65.                     pom2 = 1
  66.                 elseif room.pokr > 0 then
  67.                     room.pokr = room.pokr - 1
  68.                 elseif room.pokr == 0 then
  69.                     room.pokr = -1
  70.                     pom2 = 3
  71.                 elseif stdBorderReport() then
  72.                     if room.uztovedi > 2 then
  73.                         addm(8, "gr-m-vsechny1")
  74.                     else
  75.                         addm(10, "gr-m-svaty1")
  76.                         addv(6, "gr-v-vsechny1")
  77.                         if pokus < 2 or random(100) < 70 then
  78.                             addm(8, "gr-m-jensvaty")
  79.                         end
  80.                     end
  81.                 elseif room.tusili == 0 and room.uztovedi < 2 and random(1000) == 1 then
  82.                     room.tusili = 1
  83.                     pom2 = 2
  84.                 elseif room.uztovedi == 3 and random(30) == 1 then
  85.                     room.uztovedi = 4
  86.                     pom2 = 5
  87.                 elseif room.jestejeden == 0 and remain == 1 and random(30) == 1 then
  88.                     room.jestejeden = 1
  89.                     pom2 = 7
  90.                 elseif room.uztobude == 0 and isIn(remain, {1, 2, 3}) and random(150) == 1 then
  91.                     room.uztobude = 1
  92.                     pom2 = 6
  93.                 end
  94.             end
  95.             switch(pom2){
  96.                 [1] = function()
  97.                     addm(10, "gr-m-gral")
  98.                     addv(8, "gr-v-jiste")
  99.                     pom1 = random(2)
  100.                     addm(8, "gr-m-zare"..pom1)
  101.                     addv(8, "gr-v-nic"..pom1)
  102.                 end,
  103.                 [2] = function()
  104.                     addv(10, "gr-v-tuseni")
  105.                     addm(10, "gr-m-tuseni")
  106.                 end,
  107.                 [3] = function()
  108.                     addm(10, "gr-m-svaty0")
  109.                     addv(8, "gr-v-vsechny0")
  110.                 end,
  111.                 [4] = function()
  112.                 end,
  113.                 [5] = function()
  114.                     addm(8, "gr-m-vsechny0")
  115.                 end,
  116.                 [6] = function()
  117.                     addv(10, "gr-v-skoro0")
  118.                 end,
  119.                 [7] = function()
  120.                     addv(10, "gr-v-skoro1")
  121.                 end,
  122.             }
  123.         end
  124.     end
  125.  
  126.     -- -------------------------------------------------------------
  127.     local function prog_init_light()
  128.         light:setAnim("default", 1)
  129.         return function()
  130.             if room.uztovedi == 0 then
  131.                 if light.X ~= aura.X or light.Y ~= aura.Y + 1 then
  132.                     room.uztovedi = 1
  133.                 end
  134.             end
  135.         end
  136.     end
  137.  
  138.     -- -------------------------------------------------------------
  139.     local function prog_init_aura()
  140.         return function()
  141.             if aura.afaze >= 11 then
  142.                 aura.afaze = 0
  143.             else
  144.                 aura.afaze = aura.afaze + 1
  145.             end
  146.             aura:updateAnim()
  147.         end
  148.     end
  149.  
  150.     -- --------------------
  151.     local update_table = {}
  152.     local subinit
  153.     subinit = prog_init_room()
  154.     if subinit then
  155.         table.insert(update_table, subinit)
  156.     end
  157.     subinit = prog_init_light()
  158.     if subinit then
  159.         table.insert(update_table, subinit)
  160.     end
  161.     subinit = prog_init_aura()
  162.     if subinit then
  163.         table.insert(update_table, subinit)
  164.     end
  165.     return update_table
  166. end
  167. local update_table = prog_init()
  168.  
  169.  
  170. -- -----------------------------------------------------------------
  171. -- Update
  172. -- -----------------------------------------------------------------
  173. function prog_update()
  174.     for key, subupdate in pairs(update_table) do
  175.         subupdate()
  176.     end
  177. end
  178.  
  179.